package com.sctu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.sctu.EMSApp.R;
import com.sctu.bean.RoundBean;

import java.util.List;

/**
 * Created by fll on 2015/12/18.
 */
public class RoundClickAdapter extends BaseAdapter {

    private List<RoundBean.Results> resultsList;
    private Context context;
    private int[] img = new int[]{R.drawable.daolan_redframe,R.drawable.daolan_pinkframe,R.drawable.daolan_lightgreenframe};

    public RoundClickAdapter(List<RoundBean.Results> resultsList, Context context) {
        this.resultsList = resultsList;
        this.context = context;
    }

    @Override
    public int getCount() {
        if (resultsList != null && resultsList.get(0).getPassing().length > 0) {
            return resultsList.get(0).getPassing().length + 2;
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = LayoutInflater.from(context).inflate(R.layout.scenictour_round_after_click_item, null);

        TextView textPass = (TextView) view.findViewById(R.id.round_click_pass_content);
        TextView textPosition = (TextView) view.findViewById(R.id.round_click_position);
        TextView textName = (TextView) view.findViewById(R.id.round_click_pass_title);

        textPosition.setText(position + 1 + "" );

        if (position == 0) {
            textPass.setText(resultsList.get(0).getOrigin());
            textName.setText("起点：");
            textPosition.setBackgroundResource(R.drawable.daolan_orangeframe);
        }
        if (position == resultsList.get(0).getPassing().length + 1){
            textPass.setText(resultsList.get(0).getDestination());
            textName.setText("终点：");
            textPosition.setBackgroundResource(R.drawable.daolan_greenframe);
        }
        if(position != 0 && position != resultsList.get(0).getPassing().length + 1){
                textPass.setText(resultsList.get(0).getPassing()[position - 1]);
                textName.setText("途经：");
            for (int i = 0;i < img.length;i ++){
                textPosition.setBackgroundResource(img[i]);
            }
        }


        return view;
    }
}
